#!/bin/bash
# 这个代码既能跑amazon_reviews，也能跑trace
start_time=$(date +%s) # %s可以计算的是1970年以来的秒数

for data_name in amazon_reviews 111969901601639 111969905476917 562949953687423 562949991973241 562949986954745 562949968102112 562950076034278; do
  # 先删除原有的文件，否则需要sudo
  rm ../evaluation/${data_name}_allLoad_randomGet_put.txt
  rm ../evaluation/${data_name}_allLoad_randomGet_16_llsm.txt
  rm ../evaluation/${data_name}_allLoad_randomGet_16_baseline.txt
  rm ../evaluation/${data_name}_allLoad_randomGet_16_llsm_level.txt
  
  rm ../evaluation/${data_name}_allLoad_randomPut_put.txt
  rm ../evaluation/${data_name}_allLoad_randomPut_16_llsm.txt
  rm ../evaluation/${data_name}_allLoad_randomPut_16_baseline.txt
  rm ../evaluation/${data_name}_allLoad_randomPut_16_llsm_level.txt
  
    cd ../build/
    data_path=../db/dataset/${data_name}.txt
  ./a_allLoad_randomGet -f ${data_path} -k 16 -v 64 -d ../ssd/db_${data_name} -m 7 -w -l 3 > ../evaluation/${data_name}_allLoad_randomGet_put.txt
  
  sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
  ./a_allLoad_randomGet -f ${data_path} -k 16 -v 64 -d ../ssd/db_${data_name} -m 7 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/${data_name}_allLoad_randomGet_16_llsm.txt
  ./a_allLoad_randomGet -f ${data_path} -k 16 -v 64 -d ../ssd/db_${data_name} -m 8 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/${data_name}_allLoad_randomGet_16_baseline.txt
  
  sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
  ./a_allLoad_randomGet -f ${data_path} -k 16 -v 64 -d ../ssd/db_${data_name} -m 7 -u -n 10000 -i 5 $* > ../evaluation/${data_name}_allLoad_randomGet_16_llsm_level.txt
  
  cd ../learned-leveldb/
  python ./scripts/collect_results.py 1 ${data_name}_allLoad_randomGet_16 > ../evaluation/expr_allLoad_randomGet_${data_name}_16.txt
  cat ../evaluation/expr_allLoad_randomGet_${data_name}_16.txt
  

  cd ../build/
  ./a_allLoad_randomPut -f ${data_path} -k 16 -v 64 -d ../ssd/db_${data_name} -m 7 -w -l 3 > ../evaluation/${data_name}_allLoad_randomPut_put.txt

  sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
  ./a_allLoad_randomPut -f ${data_path} -k 16 -v 64 -d ../ssd/db_${data_name} -m 7 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/${data_name}_allLoad_randomPut_16_llsm.txt
  ./a_allLoad_randomPut -f ${data_path} -k 16 -v 64 -d ../ssd/db_${data_name} -m 8 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/${data_name}_allLoad_randomPut_16_baseline.txt

  sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
  ./a_allLoad_randomPut -f ${data_path} -k 16 -v 64 -d ../ssd/db_${data_name} -m 7 -u -n 10000 -i 5 $* > ../evaluation/${data_name}_allLoad_randomPut_16_llsm_level.txt

  cd ../learned-leveldb/
  python ./scripts/collect_results.py 1 ${data_name}_allLoad_randomPut_16 > ../evaluation/expr_allLoad_randomPut_${data_name}_16.txt
  cat ../evaluation/expr_allLoad_randomPut_${data_name}_16.txt

done

end_time=$(date +%s)
cost_time=$((end_time-start_time))
echo "$0" "运行时间：$((cost_time/60))min $((cost_time%60))s"